package com.example.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class MyDataAdapter {
    private MySQLiteOpenHelper openHelper=null;
    private SQLiteDatabase database;
    public void openDB(Context context){
    openHelper = new MySQLiteOpenHelper(context, "Student.db",null,1);
    try{
        database = openHelper.getWritableDatabase();
    }catch (Exception e){
        database = openHelper.getReadableDatabase();
    }
    }

    public void closeDB(){
        if (database!=null){
            database.close();
            database  = null;

        }
        if (openHelper != null){
            openHelper.close();
            openHelper = null;
        }
    }

    public boolean isOpen(){
        if (database!=null){
            return database.isOpen();

        }else{
            return false;
        }
    }
    public boolean isReadOnly(){
        if (database!=null){
            return database.isReadOnly();
        }else {
            return false;
        }
    }

    public int getVersion(){
        if (database!=null){
            return database.getVersion();
        }else {
            return -1;
        }
    }
    public String getPath(){
        if (database!=null){
        return database.getPath();
    }else {
            return "空";
        }
    }
}
